package com.jbh.wanandroidkotlin.activity

import android.os.Bundle
import android.widget.Toast
import com.jbh.wanandroidkotlin.R
import com.scwang.smartrefresh.layout.api.RefreshLayout
import com.scwang.smartrefresh.layout.constant.RefreshState
import com.scwang.smartrefresh.layout.header.TwoLevelHeader
import com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener
import kotlinx.android.synthetic.main.activity_favorite_list.*


class FavoriteListActivity : BaseActivity() {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_favorite_list)


        refreshLayout!!.setOnMultiPurposeListener(object : SimpleMultiPurposeListener() {
            override fun onLoadMore(refreshLayout: RefreshLayout) {
                Toast.makeText(application, "上拉加载", Toast.LENGTH_SHORT).show()
                refreshLayout.finishLoadMore(2000)
            }

            override fun onRefresh(refreshLayout: RefreshLayout) {
                Toast.makeText(application, "下拉刷新", Toast.LENGTH_SHORT).show()
                refreshLayout.finishRefresh(2000)
            }

            override fun onStateChanged(
                refreshLayout: RefreshLayout,
                oldState: RefreshState,
                newState: RefreshState
            ) {
                if (oldState == RefreshState.TwoLevel) {
                    findViewById(R.id.second_floor_content).animate().alpha(0f).duration = 1000
                }
            }
        })

        header!!.setOnTwoLevelListener {
            Toast.makeText(application, "打开二楼", Toast.LENGTH_SHORT).show()
            second_floor_content.animate().alpha(1f).duration = 2000
            second_floor_content.setOnClickListener {
                header.finishTwoLevel()
            }
            true
        }
    }
}